package com.cgs.query.server.listener

import com.cgs.query.event.QueryDefineEvent
import com.cgs.query.service.IProject2DefineService
import com.cgs.query.util.Utils
import org.springframework.beans.factory.annotation.Autowired
import org.springframework.context.ApplicationListener

/**
 * 定义监听
 */
open class QueryDefineListener : ApplicationListener<QueryDefineEvent> {

    @Autowired
    private lateinit var project2DefineServiceImpl: IProject2DefineService

    override fun onApplicationEvent(event: QueryDefineEvent?) {
        Utils.notNullAndThen(event){
            when(it.type){
                QueryDefineEvent.Type.DELETE->{
                    //删除的时候，同时移除关联表中的数据
                    project2DefineServiceImpl.deleteByDefineId(event!!.defineId!!)
                }
                QueryDefineEvent.Type.BATCH_DELETE -> TODO()
            }
        }
    }
}